package com.ldxx.mustwinlottery.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.ldxx.mustwinlottery.R;
import com.ldxx.mustwinlottery.presenter.IssueInfoPresenter;
import com.ldxx.mustwinlottery.presenter.impl.IssueInfoPresenterImpl;
import com.ldxx.mustwinlottery.service.InitDataService;
import com.ldxx.mustwinlottery.ui.view.SplashView;

/**
 * 欢迎页面
 * Created by ldxx
 * on 16/8/26.
 */
public class SplashActivity extends Activity implements SplashView {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        IssueInfoPresenter presenter = new IssueInfoPresenterImpl(this);
        presenter.getIssueInfos();
    }

    @Override
    public void afterGetIssueInfo() {
        startService();
        toMain();
        finish();
    }

    @Override
    public Context getContext() {
        return SplashActivity.this;
    }

    private void startService() {
        Intent intent = new Intent(SplashActivity.this, InitDataService.class);
        startService(intent);
    }

    private void toMain() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
            }
        }, 20000);
    }
}
